package main

import (
	"log"
	"noword/routes"
	"noword/unit"
	"path/filepath"

	"github.com/gin-gonic/gin"
)

// 配置项
var (
	backupDir  = filepath.Join(".", "wwwroot") // 备份文件存放目录
	userName   = "interlib"                    // Oracle用户名
	passWord   = "interlib"                    // Oracle密码
	sid        = "interlib"                    // Oracle SID
	retainDays = 2                             // 保留最近2天的备份
	filename   = "backup.dmp"
)

func main() {
	// 设置日志格式
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)

	// 启动定时任务
	go unit.StartScheduler(backupDir, retainDays, userName, passWord, sid, filename)

	// 初始化Gin路由
	router := gin.Default()

	// 设置路由
	routes.SetupRoutes(backupDir, router)
	// 启动HTTP服务器
	port := "8080"
	log.Printf("服务已启动，监听端口 %s\n", port)
	log.Printf("备份目录: %s\n", backupDir)

	if err := router.Run(":" + port); err != nil {
		log.Fatalf("启动HTTP服务器失败: %v", err)
	}
}
